home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks97 / WarriorsProgress.sit / Warrior’s Progress / source code / Source / Libraries / Drawing / GraphicsDeviceObject.cp < prev    next >
Text File  |  1997-06-28  |  656b  |  31 lines

  1. // GraphicsDeviceObject.cp
  2.  
  3. #ifndef GraphicsDeviceObject_h
  4. #include "GraphicsDeviceObject.h"
  5. #endif
  6. #ifndef ScreenLoop_h
  7. #include "ScreenLoop.h"
  8. #endif
  9.  
  10. GDHandle GraphicsDeviceObject::Nearest( const Rectangle& target )
  11.   {
  12.     GDHandle nearest = 0;
  13.     uint32 bestArea = 0;
  14.     uint32 bestDistance = maxuint32;
  15.     
  16.     for ( ScreenLoop screen; screen.Unfinished(); screen++ )
  17.       {
  18.         uint32 area = ( target & (*screen).Bounds() ).Area();
  19.         uint32 distance = target.TaxicabDistanceTo( (*screen).Bounds() );
  20.         
  21.         if ( area > bestArea || distance < bestDistance )
  22.           {
  23.             nearest = *screen;
  24.             bestArea = area;
  25.             bestDistance = distance;
  26.           }
  27.       }
  28.     
  29.     return nearest;
  30.   }
  31.